Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(sequencer)!: perform check tx like regular block building #1341

Closed
wants to merge 20 commits into from

Conversation

SuperFluffy
Copy link
Member

@SuperFluffy SuperFluffy commented Aug 2, 2024

Summary

This patch updates sequencer's mempool service to execute the same steps when serving an ABCI CheckTx request as it would during regular block building.

Background

The current check-tx implementation was only performing a subset of the checks that would be performed during regular block construction (specifically, during finalize-block). This means that while a check-tx would return a positive response, a subsequent and immediate execution would fail. Furthermore, with the changes in #1318 the distinction between checks and execution has been lifted, moving the current check-tx implementation further away from actual business logic.

With this patch the check-tx logic now uses exactly the same code paths as for regular block construction.

This is done by creating a new App instance with a snapshot that never gets applied to the actual storage.

Changes

  • Rename App::execute_transaction to App::deliver_tx: this moves the nomenclature closer to cometbft (and penumbra)
  • Introduce App::deliver_tx_bytes as a wrapper to the now private App:deliver_tx.
  • Rewrite crate::service::Mempool in terms of App::execute_transaction_bytes
  • Move checks for total signed transaction size to App::deliver_tx_bytes
  • Change crate::mempool::Mempool to require Arc<SignedTransaction> in its methods: this is a relatively mild change because it wrapped its argument in an Arc anyway. This is useful because App::execute_transaction_bytes returns a Arc<SignedTransacttion>
  • Drop metrics we no longer have access to (because transactionq checking now happens in a single opaque method)
  • Provide convenience methods to downcast dynamic errors to types when possible and return abci responses
  • Remove obsolete functions in transaction::checks

Testing

ChecTx is now running the same logic as the rest of the app, which reduces the need for extra tests for the mempool service.

Tests were added for the following scenarios:

  1. A valid transaction makes it into the mempool.
  2. A transaction with a nonce ahead of the current one makes it into the mempool.

More test coverage is desirable but left to a future PR.

Metrics

Removed (at present, we no longer have direct access to these)

  • CHECK_TX_REMOVED_FAILED_STATELESS
  • CHECK_TX_REMOVED_STALE_NONCE
  • CHECK_TX_REMOVED_ACCOUNT_BALANCE
  • CHECK_TX_DURATION_SECONDS with the following labels:
    • CHECK_TX_STAGE => "stateless check"
    • CHECK_TX_STAGE => "nonce check"
    • CHECK_TX_STAGE => "chain id check"
    • CHECK_TX_STAGE => "balance check"

Added (this is a coarser metrics that effectively encapsulates those above):

  • CHECK_TX_REMOVED_SPECULATIVE_DELIVER_TX
  • CHECK_TX_DURATION_SECONDS label:

Renamed (describes better what happened and contrasting to the speculative metric above):

  • CHECK_TX_REMOVED_FAILED_EXECUTION to CHECK_TX_REMOVED_FAILED_DELIVER_TX

Breaking Changelist

  • This is a breaking change because two different versions of sequencer will end up with different CheckTx results.

Related Issues

Closes #1340

@github-actions github-actions bot added the sequencer pertaining to the astria-sequencer crate label Aug 2, 2024
@SuperFluffy SuperFluffy changed the title feat(sequencer)!: perform check_tx like regular block building feat(sequencer)!: perform check tx like regular block building Aug 2, 2024
@SuperFluffy SuperFluffy added the ENG-674 Zelic's July 15 audit label Aug 2, 2024
@SuperFluffy SuperFluffy marked this pull request as ready for review August 2, 2024 15:02
@SuperFluffy SuperFluffy requested a review from a team as a code owner August 2, 2024 15:02
Base automatically changed from gh-1318 to main August 20, 2024 11:42
@joroshiba
Copy link
Member

I don't think this is the direction we want to go in, but some of what this achieves should be handled. Functionally for performance reasons with the new mempool design we want to have different levels of checks, to avoid DDOS at entry:

  1. allowed into mempool (nonce can be eventually valid, chainid, basic structure)
  2. move to pending mempool (nonce is currently valid/valid with others in pending, adequate account balance)
  3. execution (if fails evicted from mempool)

I believe some of this requires some memoization across the transaction since transactions are atomic, we need each action to be statically valid but also need the set to be valid. This requires some consideration across the transaction especially with regard to balances. There are other potential failures within a multi action transaction, but this is the primary concern.

For some edge cases around changing sudo accounts the solution is likely to disallow those actions from being in a bundle.

@joroshiba
Copy link
Member

This PR is stale because it has been open 45 days with no activity. Remove stale label or this PR will be
closed in 7 days.

@joroshiba
Copy link
Member

This PR was closed because it has been stale.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
closed-stale ENG-674 Zelic's July 15 audit sequencer pertaining to the astria-sequencer crate stale
Projects
None yet
Development

Successfully merging this pull request may close these issues.

CheckTx should use the same code paths as regular block production
3 participants